//
//  ViewController.swift
//  Swift4.0_Learn
//
//  Created by lantaiyuan on 2017/9/29.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        view.backgroundColor = UIColor.white
        //设置设置导航栏标题
        self.navigationItem.title = "0929_D01"
        //设置导航栏背景色
        self.navigationController?.navigationBar.barTintColor=UIColor.orange
    
        // MARK ---闭包的使用
        let col = Closume.init()
        let clo:(Int,Int)->Int = col.cal(opr: "+")
        let clo2:(Int,Int)->Int = col.cal(opr: "-")
        
        print("10 + 5 = \(clo(10,5))")
        print("10 - 5 = \(clo2(10, 5))")
        
        let btn = UIButton.init(frame: CGRect(x:view.center.x - 50,y:view.center.y - 15,width:100,height:30))
        btn.backgroundColor = UIColor.orange
        btn.setTitle("hello world!", for: .normal)
        btn.setTitleColor(UIColor.black, for: .normal)
        view.addSubview(btn)
        btn.addTarget(self, action: #selector(clickBtn(_:)), for: .touchUpInside)
    }
    
    /// button点击事件
    @IBAction func clickBtn(_ sender: UIButton) {
        print("click sender")
        let alertView = UIAlertController.init(title: "UIAlertController", message: "say hello!", preferredStyle: .alert)
        
        let cancelAction = UIAlertAction(title: "cancel", style: .cancel, handler: nil)
        let okAction = UIAlertAction(title: "sure", style: .default, handler:{
            (UIAlertAction) -> Void in
            self.navigationController?.pushViewController(TableViewController(), animated: true)
        })
        alertView.addAction(cancelAction)
        alertView.addAction(okAction)// 当添加的UIAlertAction超过两个的时候，会自动变成纵向分布
        self.present(alertView, animated: true, completion: nil)
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

